﻿using Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
//using UpdateTools;

namespace StationClient
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            if (CreateMutex())
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                //MethodWcf.KEY = "RssPmq&AwYcc7<98Bux";

                Application.Run(new StatisticsServer.Statistics());

                ReleaseMutex();
                //Application.Exit();
            }
            else
            {
                MessageBox.Show("该程序正在运行，请检查！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private static Mutex OnlyOne = null;
        public static bool CreateMutex()
        {
            bool result = false;
            try
            {
                Attribute attr = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(GuidAttribute));
                string guid = ((GuidAttribute)attr).Value;
                OnlyOne = new Mutex(true, guid, out result);
            }
            catch
            {
                MessageBox.Show("程序启动时发生错误！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return result;
        }

        public static void ReleaseMutex()
        {
            if (OnlyOne != null)
                OnlyOne.Close();
        }
    }
}
